package com.example.smartagriculture.controller;

import com.example.smartagriculture.utils.FFmpegService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

// API控制器
@RestController
@RequestMapping("/api")
public class StreamController {
    @Autowired
    private FFmpegService ffmpegService;

    @PostMapping("/start")
    public ResponseEntity<String> startStream(@RequestParam String streamId) {
        try {
            ffmpegService.startTranscode(streamId);
            return ResponseEntity.ok("Stream started");
        } catch (IOException e) {
            return ResponseEntity.status(500).body("Error: " + e.getMessage());
        }
    }

    @PostMapping("/stop")
    public ResponseEntity<String> stopStream() {
        ffmpegService.stopTranscode();
        return ResponseEntity.ok("Stream stopped");
    }
}
